package com.yifeng.repo.controller.excel.ysql;

import com.yifeng.repo.base.utils.converter.JacksonHelper;
import com.yifeng.repo.controller.excel.configure.ExcelLoaderProperties;
import com.yifeng.repo.controller.excel.loader.biz.BizExportAction;
import com.yifeng.repo.controller.excel.loader.dto.DataTaskConf;
import com.yifeng.repo.controller.excel.loader.dto.DataTaskDto;
import com.yifeng.repo.controller.excel.loader.dto.RowDataDto;

import java.util.*;

/**
 * Created by daibing on 2024/7/15.
 */
public class YsqlDataExportAction implements BizExportAction {


    @Override
    public DataTaskConf getTaskConf(ExcelLoaderProperties properties) {
        return new DataTaskConf(
                properties.getBatchSize(),
                properties.getQueueSize(),
                properties.getImportExcelDownTaskNumber(),
                properties.getImportLogBaseHeader(),
                properties.isImportLogFileSplit(),
                true
        );
    }

    @Override
    public String templateUrl() {
        return "C:\\Users\\00115764\\Desktop\\ysql\\YSQL数据导出验证.xlsx";
    }

    @Override
    public Map<Integer, String> templateHeader(int sheetNo) {
        Map<Integer, String> header = new LinkedHashMap<>();
        header.put(0, "id");
        header.put(1, "consult_id");
        header.put(2, "patient_phone");
        header.put(3, "patient_user_name");
        header.put(4, "patient_user_age");
        header.put(5, "patient_user_gender");
        header.put(6, "diagnosis");
        header.put(7, "department_id");
        header.put(8, "department_name");
        header.put(9, "doctor_id");
        header.put(10, "doctor_name");
        header.put(11, "reason");
        header.put(12, "apply_time");
        header.put(13, "receive_time");
        return header;
    }

    @Override
    public List<RowDataDto> source(int sheetNo, String offsetId, int size) {
        return Collections.emptyList();

    }

    private RowDataDto buildRowDataDto(int sheetNo, int rowNumber, String raw) {
        String[] split = raw.split("\t|\n");
        Map<String, String> data = new LinkedHashMap<>();
        data.put("id", String.valueOf(rowNumber));
        data.put("goods_code", split[0]);
        data.put("bar_code", split[1]);
        data.put("goods_desc", split[2]);
        data.put("category_level_1", split[3]);
        data.put("category_level_2", split[4]);
        data.put("category_level_3", split[5]);
        data.put("category_level_4", split[6]);
        data.put("tag_key", split[7]);
        data.put("tag_value", split[8]);
        data.put("tag_modify_time", split[9]);
        return new RowDataDto(sheetNo, rowNumber, data);
    }

    @Override
    public void readFinished(DataTaskDto dataTaskDto) {
        System.out.println("readFinished: " + JacksonHelper.toJson(dataTaskDto));
    }

    @Override
    public void writeFinished(DataTaskDto dataTaskDto) {
        System.out.println("writeFinished: " + JacksonHelper.toJson(dataTaskDto));
    }

    @Override
    public void totalFinished(DataTaskDto dataTaskDto) {
        System.out.println("totalFinished: " + JacksonHelper.toJson(dataTaskDto));
    }

    @Override
    public void failed(DataTaskDto dataTaskDto) {
        System.out.println("failed: " + JacksonHelper.toJson(dataTaskDto));
    }

}
